package api

import (
	"2302a/weekly/api/handler"
	"2302a/weekly/api/middleware"
	"2302a/weekly/consts"
	"2302a/weekly/pkg"
	"github.com/gin-gonic/gin"
)

func LoadRouter(r *gin.Engine) {
	r.Use(middleware.Cors())
	api := r.Group("api")
	{
		user := api.Group("user")
		{
			user.POST("register", handler.UserRegister) //注册
			user.POST("login", handler.UserLogin)       //登录
		}
		video := api.Group("video")
		{
			video.Use(pkg.JwtAuth(consts.JWT_KEY))     //中间件
			video.POST("/upload", handler.VideoUpload) //上传文件
			video.POST("/add", handler.VideoAdd)       //发布视频
			video.POST("/list", handler.VideoList)     //视频列表
		}
		give := api.Group("give")
		{
			give.Use(pkg.JwtAuth(consts.JWT_KEY))
			give.POST("/add", handler.AddGive)        //点赞
			give.POST("/cancel", handler.CancelGive)  //取消点赞
			give.GET("/details", handler.DetailsGive) //点赞状态与点赞数量
		}
		comment := api.Group("comment")
		{
			comment.Use(pkg.JwtAuth(consts.JWT_KEY))
			comment.POST("/release", handler.ReleaseComment) //发布评论
			comment.POST("/list", handler.ListComment)       //列表评论
		}
		follow := api.Group("follow")
		{
			follow.Use(pkg.JwtAuth(consts.JWT_KEY))
			follow.POST("/add", handler.AddFollow)       //点赞
			follow.POST("/cancel", handler.CancelFollow) //取消点赞
		}
	}
}
